//#include "lvgl.h"
#include "lv_russian_ime.h"


LV_FONT_DECLARE(lv_ime_font);
// 主布局（俄语字母）
static const char * russian_primary[] = {
    "й","ц","у","к","е","н","г","ш","щ","з","х","ъ",LV_SYMBOL_BACKSPACE, "\n",
    //"й","ц","у","к","е","н","г","ш","щ","з","х","ъ","\n",
    "ф","ы","в","а","п","р","о","л","д","ж","э",LV_SYMBOL_NEW_LINE, "\n",
    LV_SYMBOL_UP,"я","ч","с","м","и","т","ь","б","ю",".","'","\n",
    "1#","ё"," ",",",LV_KEYPAD_TYPE_RUSSIA,"\n",
    LV_EARTH_ICON,""
};
static const char * russian_primary_up[] = {
    "Й", "Ц", "У", "К", "Е", "Н", "Г", "Ш", "Щ", "З", "Х", "Ъ", LV_SYMBOL_BACKSPACE, "\n",
    "Ф", "Ы", "В", "А", "П", "Р", "О", "Л", "Д", "Ж", "Э", LV_SYMBOL_NEW_LINE, "\n",
    LV_SYMBOL_DOWN,"Я", "Ч", "С", "М", "И", "Т", "Ь", "Б", "Ю",".","'","\n",
    "1#","Ё"," ",",",LV_KEYPAD_TYPE_RUSSIA,"\n",
    LV_EARTH_ICON,""
};
// 二级布局（数字/符号）
static const char * russian_secondary[] = {
    "1","2","3","4","5","6","7","8","9","0","\n",
    "!","@","#","$","%","^","&","*","(",")","\n",
    "ABC","","","","","","","","","",""
};

#define LV_KB_BTN(width) LV_BTNMATRIX_CTRL_POPOVER | width
static const lv_btnmatrix_ctrl_t default_kb_ctrl_russia_map[] = {
    LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4) ,  LV_BTNMATRIX_CTRL_CHECKED | 7,
    LV_KB_BTN(3), LV_KB_BTN(3), LV_KB_BTN(3), LV_KB_BTN(3), LV_KB_BTN(3), LV_KB_BTN(3), LV_KB_BTN(3), LV_KB_BTN(3), LV_KB_BTN(3), LV_KB_BTN(3), LV_KB_BTN(4), LV_KEYBOARD_CTRL_BTN_FLAGS | 4,
    LV_KEYBOARD_CTRL_BTN_FLAGS | 4,  LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4),  LV_KB_BTN(4),  LV_KB_BTN(4),  LV_KB_BTN(4),
    LV_KEYBOARD_CTRL_BTN_FLAGS | 2, LV_KB_BTN(4),6,  LV_KB_BTN(4), LV_BTNMATRIX_CTRL_CHECKED | 2,
    LV_KEYBOARD_CTRL_BTN_FLAGS | 2
};



// 布局切换回调
static void kb_event_cb(lv_event_t *e) {
   
    lv_obj_t *kb = lv_event_get_user_data(e);
    const char *btn_txt = lv_btnmatrix_get_btn_text(kb, lv_btnmatrix_get_selected_btn(kb));
    if(strcmp(btn_txt, LV_SYMBOL_UP) == 0) 
    {
        lv_btnmatrix_set_map(kb, russian_primary_up);
    }
    else if(strcmp(btn_txt, LV_SYMBOL_DOWN) == 0) 
    {
        lv_btnmatrix_set_map(kb, russian_primary);
    }

    
   /* if (strcmp(btn_txt, "123") == 0) {
        //lv_btnmatrix_set_map(kb, russian_secondary);
        lv_keyboard_set_mode(kb,LV_KEYBOARD_MODE_TEXT_LOWER);
    } else if (strcmp(btn_txt, "ABC") == 0) {
        lv_btnmatrix_set_map(kb, russian_primary);
        lv_keyboard_set_mode(kb,LV_KEYPAD_MODE_RUSSIA_LOW);
    }*/

}
int init_russia_keypad_map(lv_obj_t *kb)
{
    if(!kb)
    {
        return -1;
    }
    // 初始化键盘布局
    lv_keyboard_set_map(kb, LV_KEYPAD_MODE_RUSSIA_LOW, russian_primary,default_kb_ctrl_russia_map);
    //设置键盘字体
    lv_obj_set_style_text_font(kb, &lv_ime_font, 0); 
    // 绑定事件
    //lv_obj_add_event_cb(kb, kb_event_cb, LV_EVENT_CLICKED, kb);
    

    return 0;
}